// common
package models_common

import (
	"martini_template/componnet"
	"martini_template/database"
)

type BaseModel struct {
	IsDeleted int `xorm:"default(0)" json:"-"`
}

func (model *BaseModel) GetList() string {
	return "hello"
}

//通过int类型的ID加载记录
func LoadInt(id int64, model interface{}) bool {
	res, lerr := database.Engine.Id(id).Where("is_deleted=?", 0).Get(model)
	if lerr != nil {
		componnet.Elogger.Println(lerr)
	}
	if res {
		return true
	} else {
		return false
	}
}

//通过string类型的ID加载记录
func LoadString(id string, model interface{}) bool {
	res, lerr := database.Engine.Id(id).Where("is_deleted=?", 0).Get(model)
	if lerr != nil {
		componnet.Elogger.Println(lerr)
	}
	if res {
		return true
	} else {
		return false
	}
}

//通过属性加载记录
func LoadByAttr(key string, val string, model interface{}) bool {
	res, lerr := database.Engine.Where(key+"=?", val).And("is_deleted=?", 0).Get(model)
	if lerr != nil {
		componnet.Elogger.Println(lerr)
	}
	if res {
		return true
	} else {
		return false
	}
}
